package com.yuyue.springFramework.note07.entity;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 定义条件类，条件为当有Service的实体时解析和注册bean
 */
public class Condition4 implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConfigurableListableBeanFactory configurableListableBeanFactory = context.getBeanFactory();
        //当有Service的实体时解析和注册bean
        boolean existsService = !configurableListableBeanFactory.getBeansOfType(IService.class).isEmpty();
        return existsService;
    }
}
